ํ”„๋ฆฌ๋žœ๋”๋ง ์˜ค๋ฅ˜

8/6/2025

๋ฌธ์ œ ์ƒํ™ฉ

์—๋Ÿฌ๋ฌธ

Error occurred prerendering page "/more/board/write". Read more: nextjs.org/docs/messages/prerender-error
ReferenceError: document is not defined
at /vercel/path0/.next/server/chunks/112.js:1:81396
at Array.forEach (<anonymous\>)
at 87731 (/vercel/path0/.next/server/chunks/112.js:1:81384)
at t (/vercel/path0/.next/server/webpack-runtime.js:1:143)
at 418 (/vercel/path0/.next/server/app/more/board/write/page.js:1:296)
at Object.t [as require] (/vercel/path0/.next/server/webpack-runtime.js:1:143)
at require (/vercel/path0/node_modules/.pnpm/next@15.3.1_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:140:10304)
at u (/vercel/path0/node_modules/.pnpm/next@15.3.1_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:92:646)
at U (/vercel/path0/node_modules/.pnpm/next@15.3.1_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:92:10632)
at W (/vercel/path0/node_modules/.pnpm/next@15.3.1_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:92:13339)
Export encountered an error on /more/board/write/page: /more/board/write, exiting the build.
โจฏ Next.js build worker exited with code: 1 and signal: null
โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1

์ฝ”๋“œ

//page.tsx
"use client";
import { useState, useRef } from "react"; 
import Editor from "./editor"; 
import Quill, { Delta } from "quill"; 
import { createBoard } from "@/lib/actions"; 

export default function Page() {
	const quillRef = useRef<Quill | null>(null); 
	const [title, setTitle] = useState(""); 
	
	const handleSave = () => { 
		const delta: Delta | null = quillRef.current?.getContents() || null; 
		const content = JSON.stringify(delta); 
		console.log("content : ", content); 
		if (title && content) {
			createBoard(title, content); 
		} 
	}; 
	
	return ( 
	<div className="container mx-auto px-4 py-8 mt-4 bg-gray-200"> 
		<div className="w-full px-10 flex text-3xl items-center relative"> 
			<div> 
				<span>์ œ๋ชฉ</span> 
				<input 
					onChange={(e) => { setTitle(e.target.value); }} 
					className="mx-2 bg-gray-50 rounded-sm py-2
					focus:outline-0 text-center border border-gray-300 shadow" >
				</input> 
			</div> 
			<div 
			className="flex justify-end gap-2 absolute right-3"> 
				<button 
					onClick={handleSave} 
					className="
					bg-blue-500 hover:bg-blue-600 text-white 
					font-medium px-6 py-2 rounded-lg text-lg 
					shadow-md" > 
					์ž‘์„ฑํ•˜๊ธฐ 
				</button> 
			</div> 
		</div> 
		<div className="my-4 bg-white shadow h-190"> 
			<Editor ref={quillRef} /> 
		</div> 
	</div> 
	); 
}
//editor.tsx
"use client";
  
import { useEffect, useRef, RefObject } from "react";
import Quill from "quill";
import "quill/dist/quill.bubble.css";
  
export default function Editor({ ref }: { ref: RefObject<Quill | null> }) {
	const containerRef = useRef<HTMLDivElement | null>(null);
	  
	useEffect(() => {
		const container = containerRef.current;
		if (container) {
			const editorContainer = container.appendChild(
			container.ownerDocument.createElement("div")
		);
		const quill = new Quill(editorContainer, { theme: "bubble" });
		  
		ref.current = quill;
		  
		return () => {
			ref.current = null;
			container.innerHTML = "";
		};
		}
	}, [ref]);
	return (
		<div className="h-full overflow-auto">
			<div ref={containerRef} className="ml-20 mt-8 mr-30" />
		</div>
	);
}

์›์ธ

write/page.tsx๋ฅผ ํ”„๋ฆฌ๋ Œ๋”๋ง ํ•  ์ˆ˜ ์—†์–ด์„œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ. ํŽ˜์ด์ง€๋ฅผ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด ๋‘˜ ๋•Œ ๊ฑฐ๊ธฐ์„œ ๋ถˆ๋Ÿฌ์˜จ quill ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ document๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” DOM API๋ฅผ ํ•„์š”๋กœ ํ•œ๋‹ค. (๊ฐ€๋ น quill ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์•ˆ์—์„œ document.getElementById ์™€ ๊ฐ™์€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค) ์ฆ‰ quill์„ ์‹ค์งˆ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” editor.tsx์—์„œ ํ€ผ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋ถˆ๋Ÿฌ์™€์„œ ๋ฌธ์ œ๊ฐ€ ๋˜๋Š”๊ฒƒ. write/page.tsx์—์„œ๋„ quill๋ฅผ ๋ถˆ๋Ÿฌ์˜ค์ง€๋งŒ ์—ฌ๊ธฐ์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์ง€๋Š” ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋˜์ง€ ์•Š์•˜๋‹ค.